package com.bdqn.tour.servlet.Hzy;

import com.bdqn.tour.pojo.HzyInvoice;
import com.bdqn.tour.service.impl.HzyInvoiceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addInvoice")
public class AddInvoiceServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/plain;charset=utf-8");

        //获取参数
        String type = req.getParameter("invoice-type");
        String invoice_Header = req.getParameter("in_header");
        String tin = req.getParameter("tin");

        //实体类
        HzyInvoice invoice = new HzyInvoice();
        invoice.setType(type);
        invoice.setInvoice_Header(invoice_Header);
        invoice.setTin(tin);

        //调用service
        int result = new HzyInvoiceServiceImpl().addInvoice(invoice);

        //返回结果
        resp.getWriter().write(result > 0 ? "添加成功" : "添加失败");
    }
}
